package cn.itcast.itcaststore.web.servlet.client;

import cn.itcast.itcaststore.exception.ActiveUserException;
import cn.itcast.itcaststore.serive.UserService;
import cn.itcast.itcaststore.serive.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/activeUser")
public class ActiveUser extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String activeCode = req.getParameter("activeCode");
        UserService userService =new UserServiceImpl();
        try {
            int i = userService.activeUser(activeCode);
            if (i==1){
                resp.sendRedirect(req.getContextPath() + "/client/activesuccess.jsp");
            }
        } catch (ActiveUserException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
